﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.ProductManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.ProductManagement.ProductLableVMs
{
    public partial class ProductLableListVM : BasePagedListVM<ProductLable_View, ProductLableSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProductLable_View>> InitGridHeader()
        {
            return new List<GridColumn<ProductLable_View>>{
                
                this.MakeGridHeader(x => x.ProductLable_ProductId).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.ProductLable_ValueName).SetTitle(@Localizer["Page.值名称"].Value),
                this.MakeGridHeader(x => x.ProductLable_ValueMode).SetTitle(@Localizer["Page.值类型"].Value),
                this.MakeGridHeader(x => x.ProductLable_Value).SetTitle(@Localizer["Page.值"].Value),
                this.MakeGridHeader(x => x.ProductLable_Pos).SetTitle(@Localizer["_Admin.DisplayOrder"].Value),
                this.MakeGridHeader(x => x.ProductLable_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.ProductLable_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProductLable_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProductLable_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProductLable_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.ProductLable_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProductLable_View> GetSearchQuery()
        {
            var query = DC.Set<ProductLable>()
                
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ValueName, x=>x.ValueName)
                .CheckEqual(Searcher.ValueMode, x=>x.ValueMode)
                .CheckContain(Searcher.Value, x=>x.Value)
                .CheckEqual(Searcher.Pos, x=>x.Pos)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ProductLable_View
                {
				    ID = x.ID,
                    
                    ProductLable_ProductId = x.ProductId,
                    ProductLable_ValueName = x.ValueName,
                    ProductLable_ValueMode = x.ValueMode,
                    ProductLable_Value = x.Value,
                    ProductLable_Pos = x.Pos,
                    ProductLable_Remark = x.Remark,
                    ProductLable_CreateTime = x.CreateTime,
                    ProductLable_UpdateTime = x.UpdateTime,
                    ProductLable_CreateBy = x.CreateBy,
                    ProductLable_UpdateBy = x.UpdateBy,
                    ProductLable_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProductLable_View: ProductLable
    {
        
        public long? ProductLable_ProductId { get; set; }
        public string ProductLable_ValueName { get; set; }
        public ValueTypeEnum? ProductLable_ValueMode { get; set; }
        public string ProductLable_Value { get; set; }
        public int? ProductLable_Pos { get; set; }
        public string ProductLable_Remark { get; set; }
        public DateTime? ProductLable_CreateTime { get; set; }
        public DateTime? ProductLable_UpdateTime { get; set; }
        public string ProductLable_CreateBy { get; set; }
        public string ProductLable_UpdateBy { get; set; }
        public bool ProductLable_IsValid { get; set; }

    }

}